Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop protobuf support for OpenMetrics #2098

Merged
merged 2 commits into from
Aug 29, 2018

Conversation

mfpierre
Copy link
Contributor

@mfpierre mfpierre commented Aug 23, 2018

Drop protobuf support for OpenMetrics (text only)

What does this PR do?

  • Drop open metrics protobuf support
  • Use native python client core.Metric objects instead of protobuf objects
ProtobufMetricFamily (old) core.Metric (new)
name name
type (int) type (string)
help (string) documentation (string)
metric ([]Metric proto objects) samples ([]tuples<name, tags, value>)

Motivation

Optimizing the text only support for open metrics

Review checklist

  • PR has a meaningful title or PR has the no-changelog label attached
  • Feature or bugfix has tests
  • Git history is clean
  • If PR impacts documentation, docs team has been notified or an issue has been opened on the documentation repo

@mfpierre mfpierre requested a review from a team as a code owner August 23, 2018 08:39
@mfpierre mfpierre force-pushed the mfpierre/openmetrics-drop-protobuf branch 2 times, most recently from 4909086 to 2ea956f Compare August 23, 2018 09:36
@mfpierre mfpierre requested a review from a team August 23, 2018 09:44
# message.type is the index in this array
# see: https://github.com/prometheus/client_model/blob/master/ruby/lib/prometheus/client/model/metrics.pb.rb
self.METRIC_TYPES = ['counter', 'gauge', 'summary', 'untyped', 'histogram']
self.METRIC_TYPES = ['counter', 'gauge', 'summary', 'histogram']
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can just make this a class constant?

custom_hostname = self._get_hostname(hostname, sample, scraper_config)
tags = self._metric_tags(metric_name, val, sample, scraper_config, hostname=custom_hostname)
if sample[self.SAMPLE_NAME].endswith("_sum"):
self.gauge("{}.{}.sum".format(scraper_config['namespace'], metric_name), val, tags=tags, hostname=custom_hostname)
else:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we still collecting {}.{}.quantile metrics?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it should work, I put the quantile in the .count like the brackets and histograms, didn't pay attention it was separated for summary, I'll change this

if label_name not in scraper_config['exclude_labels']:
tag_name = label_name
if label_name in scraper_config['labels_mapper']:
tag_name = scraper_config['labels_mapper'][label_name]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's simplify this to tag_name = scraper_config['labels_mapper'].get(label_name, label_name) while we're here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's probably some other improvement like this lying around with labels being a dict, I focused on making it work first 😁

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm trying to find some more hehe 😄
We might as well improve this class while we can!

self.gauge("{}.{}.sum".format(scraper_config['namespace'], metric_name), val, tags=tags, hostname=custom_hostname)
elif sample[self.SAMPLE_NAME].endswith("_count"):
self.gauge("{}.{}.count".format(scraper_config['namespace'], metric_name), val, tags=tags, hostname=custom_hostname)
elif sample[self.SAMPLE_NAME].endswith("_bucket") and scraper_config['send_histograms_buckets']:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can probably just merge these two conditionals into:
elif sample[self.SAMPLE_NAME].endswith("_count") or (sample[self.SAMPLE_NAME].endswith("_bucket") and scraper_config['send_histograms_buckets']):

@mfpierre mfpierre force-pushed the mfpierre/openmetrics-drop-protobuf branch 2 times, most recently from 8438763 to 1769441 Compare August 23, 2018 14:39

def process_metric(self, message, scraper_config, metric_transformers=None):
for sample in metric.samples:
for label_name in scraper_config['_watched_labels'].intersection(set(sample[self.SAMPLE_LABELS].keys())):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With how many lookups we make to sample[self.SAMPLE_LABELS], we should probably just set it to a variable haha

And I think we can do this in multiple functions. What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rishabh while I agree it'll be better for readability, I'm not sure about the memory footprint of a new variable containing labels.
the lookup for sample[self.SAMPLE_LABELS] is O(1)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the footprint isn't a concern, it's just readability :)

for label in metric.label:
if label.name == scraper_config['label_to_hostname']:
return label.value
if scraper_config['label_to_hostname'] in sample[self.SAMPLE_LABELS]:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just merge these two conditions together.

@mfpierre mfpierre force-pushed the mfpierre/openmetrics-drop-protobuf branch 2 times, most recently from 8d0f587 to 12cb681 Compare August 23, 2018 16:55
_met = _rate.metric.add()
_met.gauge.value = 42
_rate = GaugeMetricFamily('my_rate', 'Random rate')
_rate.add_metric([], 42)
check = mocked_prometheus_check
mocked_prometheus_scraper_config['rate_metrics'] = ["my_rate"]
Copy link

@rishabh rishabh Aug 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can get rid of this since rate_metrics isn't a thing anymore.

@mfpierre mfpierre force-pushed the mfpierre/openmetrics-drop-protobuf branch from 12cb681 to a11fdb8 Compare August 24, 2018 08:28
@mfpierre mfpierre force-pushed the mfpierre/openmetrics-drop-protobuf branch from a11fdb8 to 99f2a1d Compare August 28, 2018 12:54
@codecov-io
Copy link

codecov-io commented Aug 28, 2018

Codecov Report

Merging #2098 into master will decrease coverage by 17.06%.
The diff coverage is 91.52%.

Impacted file tree graph

rishabh
rishabh previously approved these changes Aug 28, 2018
@mfpierre mfpierre merged commit c21e8bd into master Aug 29, 2018
@mfpierre mfpierre deleted the mfpierre/openmetrics-drop-protobuf branch August 29, 2018 15:00
shraykay pushed a commit to shraykay/integrations-core that referenced this pull request Aug 30, 2018
* Drop protobuf support for OpenMetrics (text only) and optimize for text support
nmuesch pushed a commit that referenced this pull request Nov 1, 2018
* Drop protobuf support for OpenMetrics (text only) and optimize for text support
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants